package try_;

/**
 * @Author 小闽
 * @Date 2024/9/23 17:38
 * @PackageName: try_
 * @ClassName: TryCatchExercise03
 * @Description: 异常练习03
 * @Version 1.0
 */
public class TryCatchExercise03 {
    public static void main(String[] args) {
        System.out.println(ExceptionExercise03.method());
    }
}
class ExceptionExercise03{
    public static int method(){
        int i = 1;
        try{
            i++; // i=2
            String[] names = new String[3];
            if (names[1].equals("tom")){ // 出现空指针异常
                System.out.println(names[1]);
            }else{
                names[3] = "苏宁易购";
            }
            return 1;
        }catch (ArrayIndexOutOfBoundsException e){
            return 2;
        }catch (NullPointerException e){
            return ++i; // i=3,并且返回 i=3,在底层中
        }finally {
            ++i; // i=4
            System.out.println("i=" + i); // 在这里输出 i=4
        }
    }
}